package com.swx.identityservice.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.swx.identityservice.service.CrudService;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public class CrudServiceImpl<Entity> implements CrudService<Entity> {
    @Autowired
    private  Mapper<Entity> mapper;

    @Override
    public List<Entity> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public Entity selectByPrimaryKey(Object key) {
        return mapper.selectByPrimaryKey(key);
    }

    @Override
    public PageInfo<Entity> selectEntitysByPage(int pageIndex, int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        List<Entity> entities = mapper.selectAll();
        PageInfo<Entity> pageInfo = new PageInfo<>(entities);
        return pageInfo;
    }

//    @Override
//    public PageInfo<Entity> selectEntitysByPage(int pageIndex, int pageSize, String sort) {
//        PageHelper.startPage(pageIndex, pageSize, sort);
//        List<Entity> entities = mapper.selectAll();
//        PageInfo<Entity> pageInfo = new PageInfo<>(entities);
//        return pageInfo;
//    }

    @Override
    public PageInfo<Entity> selectEntitysByPage(int pageIndex, int pageSize, List<Entity> entities) {
        PageHelper.startPage(pageIndex, pageSize);

        PageInfo<Entity> pageInfo = new PageInfo<>(entities);
        return pageInfo;
    }

    @Override
    public int insert(Entity insert) {
        return mapper.insert(insert);
    }

    @Override
    public int insertSelective(Entity entity) {
        return mapper.insertSelective(entity);
    }

    @Override
    public int updateByPrimaryKey(Entity entity) {
        return mapper.updateByPrimaryKey(entity);
    }

    @Override
    public int updateByPrimaryKeySelective(Entity entity) {
        return mapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public int deleteByPrimaryKey(Object key) {
        return mapper.deleteByPrimaryKey(key);
    }
}
